const errorTypes = require('../contants/error-types')
const BannerModel = require('../models/banner.model')

class BannerMiddleware {
  async HandleBannerShowImg(ctx, next) {

    const { bannerShowImg } = ctx.request.params

    const isExistedBanner = await BannerModel.checkBanner(bannerShowImg)

    // 处理 banner 不存在的情况
    if (!isExistedBanner) {
      const error = new Error(errorTypes.BANNER_DOES_NOT_EXIST)
      return ctx.app.emit('error', error, ctx)
    }

    await next()
  }
}

module.exports = new BannerMiddleware()





